package com.shucoin.www.tycoin.ui.home.trade;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.shucoin.www.tycoin.BaseFragment;
import com.shucoin.www.tycoin.R;
import com.shucoin.www.tycoin.adapter.DepthAdapter;
import com.shucoin.www.tycoin.bean.BidsBean;
import com.shucoin.www.tycoin.ui.history.HistoryAt;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by happy on 2017/8/26.
 */

public class ParentTradeFt extends BaseFragment implements View.OnClickListener, IViewTrade {
    Unbinder unbinder;
    TextView textHisttory;
    @BindView(R.id.text_toobar_left)
    TextView textToobarLeft;
    @BindView(R.id.text_toobar_title)
    TextView textToobarTitle;
    @BindView(R.id.spinner)
    Spinner spinner;
    @BindView(R.id.text_toobar_right)
    TextView textToobarRight;
    @BindView(R.id.tv_balance)
    TextView tvBalance;
    @BindView(R.id.tv_show)
    TextView tvShow;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.recycler_top)
    RecyclerView recyclerTop;
    @BindView(R.id.recycler_bolew)
    RecyclerView recyclerBolew;
    @BindView(R.id.parent_info)
    LinearLayout parentInfo;
    private RecyclerView recycler_Top;
    private List<BidsBean> depthListBuy = new ArrayList<>();
    private List<BidsBean> depthListAsks = new ArrayList<>();
    private DepthAdapter depthAdapterTop;
    private DepthAdapter depthAdapterBelow;
    TradeP tradeP = new TradeP();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.layout_fragment_trade, null);
        recycler_Top = (RecyclerView) rootView.findViewById(R.id.recycler_top);
        textHisttory = (TextView) rootView.findViewById(R.id.text_toobar_right);
        textHisttory.setOnClickListener(this);
        unbinder = ButterKnife.bind(this, rootView);
        initRecyclerView();
        tradeP.setiViewTrade(this);
        return rootView;
    }


    void initRecyclerView() {
        tabLayout.addTab(tabLayout.newTab().setText("市价"));
        tabLayout.addTab(tabLayout.newTab().setText("委托"));
        depthAdapterTop = new DepthAdapter(depthListBuy);
        depthAdapterBelow = new DepthAdapter(depthListAsks);
        recycler_Top.setLayoutManager(new LinearLayoutManager(getActivity()));
        recycler_Top.setNestedScrollingEnabled(false);
        recycler_Top.setAdapter(depthAdapterTop);
        recyclerBolew.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerBolew.setNestedScrollingEnabled(false);
        recyclerBolew.setAdapter(depthAdapterBelow);
    }


    @Override
    public void onStart() {
        super.onStart();

        tradeP.getDepthInfo("ethcny", "step1");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.text_toobar_right:
                startActivity(new Intent(getActivity(), HistoryAt.class));
                break;
        }
    }


    @Override
    public BaseQuickAdapter getAdapter(int type) {
        switch (type) {
            case 0:
                return depthAdapterTop;
            case 1:
                return depthAdapterBelow;
        }
        return null;
    }
}
